package controller;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import au.com.bytecode.opencsv.CSVReader;
import entity.Student;

public class BootstrapCtrl {

	private StudentCtrl studentCtrl;
	private CourseCtrl courseCtrl;
	private SectionCtrl sectionCtrl;
	private BidCtrl bidCtrl;

	public BootstrapCtrl() {
		studentCtrl = new StudentCtrl();
	}

	public void startBootstrap() {
		insertStudentsFromCsv();
		insertCourseFromCsv();
		insertSectionFromCsv();
		insertPreRequisitesFromCsv();
		insertCompletedCoursesFromCsv();
		insertCompletedCoursesFromCsv();
		processBidsFromCsv();
	}

	private void insertStudentsFromCsv() {
		CSVReader reader = null;
		try {
			reader = new CSVReader(new FileReader("data/student.csv"));
			String[] lineData;
			reader.readNext(); // discard header
			while ((lineData = reader.readNext()) != null) {

				// validate if any field is blank
				// send to conrtoller for insertion which will do further
				// validation

				studentCtrl.addStudent(lineData[0], lineData[1], lineData[2],
						lineData[3], Double.parseDouble(lineData[4]));

				Student s = new Student(lineData[0], lineData[1], lineData[2],
						lineData[3], Double.parseDouble(lineData[4]));
				System.out.println(s.toString());
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (NumberFormatException e) {
			// TODO this catach should not be here.
			e.printStackTrace();
		}

	}

	private void insertCourseFromCsv() {

	}

	private void insertSectionFromCsv() {

	}

	private void insertPreRequisitesFromCsv() {

	}

	private void insertCompletedCoursesFromCsv() {

	}

	private void processBidsFromCsv() {

	}

}
